﻿using Newtonsoft.Json;
using System.IO;

namespace FolderTag.Core
{
    public class SystemConfig
    {
        private static string _ConfigPath = "./Config.json";

        public static SystemConfig Config { get; set; }


        public SystemConfig()
        {
            ShowAllFile = false;
        }

        public bool ShowAllFile { get; set; }

        public static void Init()
        {
            SystemConfig config = new SystemConfig();
            using (var fs = File.Open(_ConfigPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                using (var sr = new StreamReader(fs))
                {
                    string configData = sr.ReadToEnd();
                    if (!string.IsNullOrEmpty(configData))
                        config = JsonConvert.DeserializeObject<SystemConfig>(configData);
                    Config = config;
                }
            }
        }

        public static void Save()
        {
            File.WriteAllText(_ConfigPath, JsonConvert.SerializeObject(Config));
        }
    }
}
